-
Notifications
You must be signed in to change notification settings - Fork 167
add input file tail #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
add input file tail #645
Conversation
Signed-off-by: Jem Davies <jemsot@gmail.com>
Signed-off-by: Jem Davies <jemsot@gmail.com>
Signed-off-by: Jem Davies <jemsot@gmail.com>
Signed-off-by: Jem Davies <jemsot@gmail.com>
Replace errChan draining with doneChan synchronization to ensure watch() goroutine exits before closing file handle. Also fix file handle leaks in newTail() error paths.
ed975dc to
bbd8915
Compare
Signed-off-by: Jem Davies <jemsot@gmail.com>
|
|
||
| if !os.SameFile(t.fileInfo, tempInfo) { | ||
| if t.logger != nil { | ||
| t.logger.Info(fmt.Sprintf("Handling rotation for %v", t.path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we downgrade these rotation logs to the debug level?
|
|
||
| pos, err := t.file.Seek(0, io.SeekCurrent) | ||
| if err != nil { | ||
| return fmt.Errorf("seek file: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps some of these errors should have more info added:
| return fmt.Errorf("seek file: %w", err) | |
| return fmt.Errorf("failed to set seek on %s: %w", t.file.Name(). , err) |
| line, err := t.reader.ReadBytes('\n') | ||
| line = bytes.TrimRight(line, "\r\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason why we're exclusively using \n as a delimiter here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes could have a config option for that
| file *os.File | ||
| fileInfo os.FileInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on using the *service.FS from the mgr *service.Resources instead for file reading?
i.e
mgr.FS().OpenFile()This way we're relying on our FS fixtures instead of the os package
| } | ||
| } | ||
|
|
||
| func (fti *FileTailInput) Close(ctx context.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this idempotent? Also, we should probably select on the ctx.Done() to allow returning early if the ctx is cancelled
Some context: I had decided to implement this as a simpler alternative to #514.